import Vue from 'vue'
import Router from 'vue-router'
// import pageFirst from '@/pages/page-first/index'
// import pageSecond from '@/pages/page-second/index'

Vue.use(Router)
// 重写路由方法 在当前页面点击logo地址不更新的情况下 避免报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    // {
    //   path: '**',   // 错误路由
    //   redirect: '/first'   //重定向
    // },
    {
      path: '/login',
      name: 'login',
      component: () =>
        import('@/pages/login/index.vue'),
      meta: { title: '登录' }
    },
    // 内容区域
    {
      path: '/container',
      name: 'container',
      meta: { title: '熊先森' },
      component: () =>
        import('@/pages/container/index.vue'),
      children: [
        {
          path: '/',
          redirect: '/studentInfos',
        },
        // 公告轮播图的详情页
        {
          path: '/viewBox',
          name: 'viewBox',
          meta: { title: '公告信息' },
          component: () =>
            import('@/components/topBar/components/viewBox/index.vue'),
        },
        // 学生基本信息
        {
          path: '/studentInfos',
          name: 'studentInfos',
          meta: { title: '学生信息查询' },
          component: () =>
            import('@/pages/studentInfos/index.vue'),
          children: [
            {
              path: '/studentInfosLook',
              name: 'studentInfosLook',
              meta: { title: '学生基本信息' },
              component: () =>
                import('@/pages/studentInfos/indexLook.vue'),
            }
          ]
        },
        // 学生成绩排名
        {
          path: '/grade',
          name: 'grade',
          meta: { title: '学生成绩排名' },
          component: () =>
            import('@/pages/grade/index.vue')
        },
        // 学科成绩排名
        {
          path: '/subject',
          name: 'subject',
          meta: { title: '学科成绩排名' },
          redirect: 'english',
          component: () =>
            import('@/pages/subject/index.vue'),
          children: [
            // {
            //   path: '/',
            //   redirect: '/english'
            // },
            // 英语成绩
            {
              path: 'english',
              name: 'english',
              meta: { title: '英语成绩' },
              component: () =>
                import('@/pages/subject/english/index.vue'),
            },
            // 数学成绩
            {
              path: 'math',
              name: 'math',
              meta: { title: '数学成绩' },
              component: () =>
                import('@/pages/subject/math/index.vue'),
            },
            // 语文成绩
            {
              path: 'chinese',
              name: 'chinese',
              meta: { title: '语文成绩' },
              component: () =>
                import('@/pages/subject/chinese/index.vue'),
            },
          ]
        },
        // 班级
        {
          path: '/seatMap',
          name: 'seatMap',
          meta: { title: '座位图' },
          component: () =>
            import('@/pages/class/seatMap/index.vue'),
        },
        // 题库
        {
          path: '/chinese',
          name: 'chinese',
          meta: { title: '语文' },
          component: () =>
            import('@/pages/questionBank/chinese/index.vue')
        },
        {
          path: '/math',
          name: 'math',
          meta: { title: '数学' },
          component: () =>
            import('@/pages/questionBank/math/index.vue')
        },
        {
          path: '/english',
          name: 'english',
          meta: { title: '英语' },
          component: () =>
            import('@/pages/questionBank/english/index.vue')
        },
        // 公告发布
        {
          path: '/announce',
          name: 'announce',
          meta: { title: '公告发布' },
          component: () =>
            import('@/pages/announce/index.vue')
        },
        // 数据可视化
        {
          path: '/dataview',
          name: 'dataview',
          meta: { title: '数据可视化' },
          component: () =>
            import('@/pages/dataview/index.vue')
        },
        // 系统设置
        {
          path: '/userinfos',
          name: 'userinfos',
          meta: { title: '个人资料' },
          component: () =>
            import('@/pages/setting/userinfos/index.vue')
        },
        {
          path: '/permissions',
          name: 'permissions',
          meta: { title: '权限设置' },
          component: () =>
            import('@/pages/setting/permissions/index.vue')
        },
        {
          path: '/role',
          name: 'role',
          meta: { title: '角色设置' },
          component: () =>
            import('@/pages/setting/role/index.vue')
        },
      ]

    },

  ]
})
// router.beforeEach((to, from, next) => {
//   console.log(to);

//   // 如果用户访问的登录页面，直接放行
//   if (to.path === '/login')
//     return next();

//   // 从sessionStorage 中获取保存的 token 值
//   const tokenStr = window.localStorage.getItem('token');
//   console.log(tokenStr);

//   //  没有token，强制跳转到登录页面
//   if (tokenStr)
//     return next('/login');

//   next();

// })
export default router
